package com.tan.model.vo;

import com.tan.model.domain.UserInfo;
import com.tan.model.mongo.Comment;
import com.tan.model.mongo.VideoComment;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class VideoCommentVo implements Serializable {

    private String id; //视频评论的编号
    private String avatar; //头像
    private String nickname; //昵称


    private String content; //评论
    private String createDate; //评论时间
    private Integer likeCount; //点赞数
    private Integer hasLiked; //是否点赞（1是，0否）

    public static VideoCommentVo init(UserInfo userInfo, VideoComment item) {
        VideoCommentVo vo = new VideoCommentVo();
        BeanUtils.copyProperties(userInfo, vo);
        BeanUtils.copyProperties(item, vo);
        Date date = new Date(item.getCreated());
        vo.setCreateDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date));
        vo.setId(item.getId().toHexString());
        vo.setHasLiked(0);
        return vo;
    }
}